﻿Imports System.Windows.Forms

Partial Public Class ReferencesManager

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim dlg As New Dialogs.InputDialog
        dlg.Input = "System.dll"
        dlg.Title = "Add reference"
        dlg.Description = "Write the name of the reference"
        If dlg.ShowDialog = Forms.DialogResult.OK Then
            Try
                Dim Ref As New Cintie.ScriptEngine.Reference
                Ref.RealUri = dlg.Input
                Ref.RelativeUri = dlg.Input
                CurScript.AddReference(Ref)
                ListBox1.Items.Add(Ref)
            Catch Ex As Exception
                MsgBox(Ex.Message)
            End Try
        End If


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Dim Open As New OpenFileDialog
        If Open.ShowDialog = Forms.DialogResult.OK Then
            Try
                If CanSaveScript = False Then
                    Dim _r As New Cintie.ScriptEngine.Reference
                    Dim F As New IO.FileInfo(Open.FileName)
                    _r.RealUri = ScriptDir.FullName & "\" & F.Name
                    _r.RelativeUri = "\" & ScriptDir.Name & "\" & F.Name
                    CurScript.AddReference(_r)
                    ListBox1.Items.Add(_r)
                Else
                    Dim F As New IO.FileInfo(Open.FileName)
                    Dim _r As New Cintie.ScriptEngine.Reference
                    _r.RealUri = ScriptDir.FullName & "\" & F.Name
                    _r.RelativeUri = "\" & ScriptDir.Name & "\" & F.Name
                    CurScript.AddReference(_r)
                    ListBox1.Items.Add(_r)
                    My.Computer.FileSystem.CopyFile(Open.FileName, ScriptDir.FullName & "\" & F.Name)
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button3.Click
        Try
            CurScript.RemoveReference(ListBox1.SelectedItem)
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
